package com.laxcen.facestaticcheck;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.laxcen.facestaticcheck.engine.FaceCheckManager;
import com.laxcen.facestaticcheck.task.TaskManager;

/**
 * 人脸识别测试页面
 */
public class SelectActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select);
        TaskManager.getInstance().init();
    }


    private String currentUserNo = "N100000020000";//当前用户名
    private String face64 = "";
    /**
     * 注册用户
     * @param view
     */
    public void register(View view){
        FaceCheckManager.getInstance().startRegister(this, (isSuccess, msg) -> {
            if(isSuccess){
                //这里返回的是人脸数据
                face64 = msg;
                Log.e("registerFace->","人脸数据:"+face64);
                Toast.makeText(SelectActivity.this,"人脸注册成功!",Toast.LENGTH_SHORT).show();
                //这里把人脸数据传到服务器...
            }else{
                Toast.makeText(SelectActivity.this,"注册失败!错误信息:"+msg,Toast.LENGTH_SHORT).show();
            }
        });
    }

    /**
     * 人脸识别
     * @param view
     */
    public void compare(View view){
        FaceCheckManager.getInstance().startCompare(this,face64,((isSuccess, msg) -> {
            if(isSuccess){
                Toast.makeText(SelectActivity.this,"人脸验证本人成功!跳到对应页面...",Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(SelectActivity.this,"人脸验证本人失败!错误信息:"+msg,Toast.LENGTH_SHORT).show();
            }
        }));
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //处理返回信息
        FaceCheckManager.getInstance().onActivityResult(requestCode,resultCode,data);
    }
}